package edu.cuit.campus.config;

import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * web.xml
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/8/15 10:35
 */
public class CampusApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    //spring root ioc配置
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringRootApplicationContextConfig.class};
    }

    //spring mvc配置类
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringServletApplicationContextConfig.class};
    }

    //前端控制器的拦截请求的url
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    /**
     * 配置文件上传的相关属性,文件上传路径需要在程序中指定服务器的真实路径
     * @param registration Servlet动态加载配置
     */
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        //设置允许上传的单个文件大小 5M
        var singleMax = 5 * 1024 * 1024;
        //设置允许上传的总文件大小 20M
        var totalMax = 20 * 1024 * 1024;
        registration.setMultipartConfig(
                new MultipartConfigElement(null, singleMax, totalMax,0));
    }

}
